package com.course.servlet;

import com.course.entity.Teacher;
import com.course.service.TeacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/guanliyuan_teacher_manage")
public class GuanliyuanTeacherManageServlet extends HttpServlet {
    private final TeacherService teacherService = new TeacherService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        List<Teacher> teachers;

        String teacherNumber = request.getParameter("teacherNumber");
        String teacherName = request.getParameter("teacherName");
        String department = request.getParameter("department");

        if (teacherNumber != null && !teacherNumber.trim().isEmpty() ||
            teacherName != null && !teacherName.trim().isEmpty() ||
            department != null && !department.trim().isEmpty()) {
            teachers = teacherService.searchTeachers(teacherNumber, teacherName, department);
        } else {
            teachers = teacherService.getAllTeachers();
        }

        request.setAttribute("teachers", teachers);
        request.getRequestDispatcher("guanliyuan_teacher_manage.jsp").forward(request, response);
    }
} 